package com.server.service.impl;

import com.common.constant.BaseConstant;
import com.pojo.dto.UserInfoDTO;
import com.pojo.entity.UserInfo;
import com.pojo.vo.UserInfoBaseVO;
import com.server.mapper.UserInfoMapper;
import com.server.service.UserInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;

@Service
public class UserInfoServiceImpl implements UserInfoService {
    @Autowired
    UserInfoMapper userInfoMapper;
    @Override
    public Integer insertUserInfo(Integer userId) {
        UserInfo userInfo = UserInfo.builder().userId(userId)
                .avatar(BaseConstant.DEFAULT_AVATAR)
                .nickName(BaseConstant.BASE_NICK_NAME + 10000+userId)
                .sex(1)
                .createTime(LocalDate.now()).build();

        return userInfoMapper.insertUserInfo(userInfo);
    }

    @Override
    public Integer updateUserInfo(UserInfo userInfo) {
        return userInfoMapper.updateUserInfo(userInfo);
    }

    @Override
    public UserInfo selectByUserId(Integer userId) {
        return userInfoMapper.selectByUserId(userId);
    }

    @Override
    public UserInfoBaseVO selectBaseUserInfo(Integer userId) {
        return userInfoMapper.selectBaseUserInfoByUserId(userId);
    }
}
